package com.easyattendance.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="TBL_TIMETABLE")
@IdClass(TimeTablePK.class)
public class TimeTable implements Serializable
{

	@Id
	@Column(name="day_of_week",nullable=false,length=10)
	private String day_of_week;
	
	@Id
	@Column(name="time_slot",nullable=false)
	private Date time_slot;

	@Id
	@GenericGenerator(name="subject_id",strategy="foreign")
	@Column(name="subject_id",length=6,nullable=false)
	private String subject_id;
	
	@ManyToOne
	@JoinColumn(name="subject_id", insertable=false, updatable=false, referencedColumnName="subject_id")
	private Subject subject;
	
	@Id
	@GenericGenerator(name="teacher_id",strategy="foreign")
	@Column(name="teacher_id",length=15)
	private String teacher_id;
	
	@ManyToOne
	@JoinColumn(name="teacher_id", insertable=false, updatable=false, referencedColumnName="teacher_id")
	private Teacher teacher;
	
	@ManyToOne
	@JoinColumn(name="section_id")
	private Section section;
	
	@ManyToOne
	@JoinColumn(name="class_id")
	private Class classObj;
	
	

	public TimeTable() {
		super();
	}

	
	
	public TimeTable(String day_of_week, Date time_slot, String teacherId,
			Subject subject, Teacher teacher, Section section, Class classObj) {
		super();
		this.day_of_week = day_of_week;
		this.time_slot = time_slot;
		this.teacher_id = teacherId;
		this.subject = subject;
		this.teacher = teacher;
		this.section = section;
		this.classObj = classObj;
	}



	public String getDay_of_week() {
		return day_of_week;
	}

	public void setDay_of_week(String day_of_week) {
		this.day_of_week = day_of_week;
	}

	public Date getTime_slot() {
		return time_slot;
	}

	public void setTime_slot(Date time_slot) {
		this.time_slot = time_slot;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	public String getSubject_id() {
		return subject_id;
	}
	public void setSubject_id(String subject_id) {
		this.subject_id = subject_id;
	}
	
	public String getTeacher_id() {
		return teacher_id;
	}
	public void setTeacher_id(String teacher_id) {
		this.teacher_id = teacher_id;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public Class getClassObj() {
		return classObj;
	}

	public void setClassObj(Class classObj) {
		this.classObj = classObj;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((day_of_week == null) ? 0 : day_of_week.hashCode());
		result = prime * result
				+ ((section == null) ? 0 : section.hashCode());
		result = prime * result + ((subject == null) ? 0 : subject.hashCode());
		result = prime * result
				+ ((time_slot == null) ? 0 : time_slot.hashCode());
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		TimeTable other = (TimeTable) obj;
		if (day_of_week.equals(other.day_of_week) && section.equals(other.section) && subject.equals(other.subject)
				&& time_slot.equals(other.time_slot) && teacher.equals(other.teacher) ) {
			return true;
		}
		else {
			return false;
		}
		
	}
	
	
	

}

